import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MaxminReduce extends Reducer<Text, IntWritable,Text, Text> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
         List<Integer> list = new ArrayList(); //用list存储成绩
        int zcj =0;
        for (IntWritable stdvalues:values){
            list.add(stdvalues.get());
            zcj+=stdvalues.get();
        }
        int avg = zcj/list.size();
        Integer max = Collections.max(list);
        Integer min = Collections.min(list);
        context.write(key,new Text("最高分:"+max+" 平均分:"+avg+" 最低分:"+min));

    }
}
